package org.geometerplus.zlibrary.text.view.style;

import org.geometerplus.zlibrary.core.library.ZLibrary;
import org.geometerplus.zlibrary.core.options.ZLBooleanOption;
import org.geometerplus.zlibrary.core.options.ZLIntegerRangeOption;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.text.model.ZLTextAlignmentType;
import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
import org.geometerplus.zlibrary.text.view.ZLTextStyle;


public class ZLTextBaseStyle
        extends
        ZLTextStyle
{
	private static final String       GROUP                 = "Style";
	private static final String       OPTIONS               = "Options";
	
	public final ZLBooleanOption      AutoHyphenationOption = new ZLBooleanOption(OPTIONS, "AutoHyphenation", true);
	
	public final ZLBooleanOption      BoldOption            = new ZLBooleanOption(GROUP, "Base:bold", false);
	public final ZLBooleanOption      ItalicOption          = new ZLBooleanOption(GROUP, "Base:italic", false);
	public final ZLBooleanOption      UnderlineOption       = new ZLBooleanOption(GROUP, "Base:underline", false);
	public final ZLBooleanOption      StrikeThroughOption   = new ZLBooleanOption(GROUP, "Base:strikeThrough", false);
	public final ZLIntegerRangeOption AlignmentOption       = new ZLIntegerRangeOption(GROUP, "Base:alignment", 1, 4, ZLTextAlignmentType.ALIGN_JUSTIFY);
	public final ZLIntegerRangeOption LineSpaceOption       = new ZLIntegerRangeOption(GROUP, "Base:lineSpacing", 5, 20, 14);
	
	public final ZLStringOption       FontFamilyOption;
	public final ZLIntegerRangeOption FontSizeOption;
	
	public ZLTextBaseStyle(String fontFamily, int fontSize) {
		super(null, ZLTextHyperlink.NO_LINK);
		FontFamilyOption = new ZLStringOption(GROUP, "Base:fontFamily", fontFamily);
		fontSize = fontSize * ZLibrary.Instance().getDisplayDPI() / 320 * 2;
		FontSizeOption = new ZLIntegerRangeOption(GROUP, "Base:fontSize", 18, Math.max(100, fontSize * 2), fontSize);
	}
	
	@Override
	public String getFontFamily() {
		return FontFamilyOption.getValue();
	}
	
	public int getFontSize() {
		return FontSizeOption.getValue();
	}
	
	@Override
	public int getFontSize(ZLTextMetrics metrics) {
		return getFontSize();
	}
	
	@Override
	public boolean isBold() {
		return BoldOption.getValue();
	}
	
	@Override
	public boolean isItalic() {
		return ItalicOption.getValue();
	}
	
	@Override
	public boolean isUnderline() {
		return UnderlineOption.getValue();
	}
	
	@Override
	public boolean isStrikeThrough() {
		return StrikeThroughOption.getValue();
	}
	
	@Override
	public int getLeftIndent() {
		return 0;
	}
	
	@Override
	public int getRightIndent() {
		return 0;
	}
	
	@Override
	public int getFirstLineIndentDelta() {
		return 0;
	}
	
	@Override
	public int getFirstLineSpacePercent() {
		return LineSpaceOption.getValue() * 2;
	}
	
	@Override
	public int getLineSpacePercent() {
		return LineSpaceOption.getValue() * 10;
	}
	
	@Override
	public int getVerticalShift() {
		return 0;
	}
	
	@Override
	public int getSpaceBefore() {
		return 0;
	}
	
	@Override
	public int getSpaceAfter() {
		return 0;
	}
	
	@Override
	public byte getAlignment() {
		return (byte) AlignmentOption.getValue();
	}
	
	@Override
	public boolean allowHyphenations() {
		return true;
	}
}
